library(AnnotationDbi)
# org.<Ab>.<>.db: organism database
# Ab: abbr for organism name
# id: type of central identifier. eg for Entrez Gene
library(org.Mm.eg.db)

# columns() to show annotation names ----------
columns(org.Mm.eg.db)

## explain the keytypes
help('MGI')

# keytypes() output is the same as columns() ----------
keytypes(org.Mm.eg.db)

# keys() get all keys for a keytypes ------
org.Mm.eg.db |>
  keys('PATH') |>
  glimpse()

# select() map for selected keytypes ----------
## response to ROS
symbol.ros <- org.Mm.eg.db |>
  select(keys = 'GO:0000302',
         keytype = 'GO',
         columns = 'SYMBOL') |>
  pull(SYMBOL) |>
  unique()

symbol.ros |>
  head()

# GO.db ----------
library(GO.db)

keytypes(GO.db)

## search go id from term text
keys(GO.db, 'TERM') |>
  str_subset('reactive oxygen') |>
  select(x = GO.db, keys = _,
         keytype = 'TERM', columns = 'GOID')
